<template>
  <div class="index-icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div class="index-icon" v-for="icon of page" :key="icon.id">
          <div class="icon-img">
            <img class="icon-imgContent" :src="icon.imgUrl" />
          </div>
          <p class="icon-text">
            {{icon.desc}}
          </p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((icon, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(icon)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .index-icons >>> .swiper-container
    width 100%
    height 0
    padding-bottom 50%
  .index-icons
    margin-top .2rem
    .index-icon
      position relative
      width 25%
      height 0
      padding-bottom 25%
      overflow hidden
      float left
      .icon-img
        position absolute
        top 0
        right 0
        left 0
        bottom .44rem
        box-sizing border-box
        padding .1rem
        .icon-imgContent
          height 100%
          margin auto
          display block
      .icon-text
        position absolute
        right 0
        left 0
        bottom 0
        height .44rem
        line-height .44rem
        text-align center
        color $textColor
        ellipsis()
</style>
